def get_index_previous_timestamp(data_in, datetime_target, idx_start, idx_limit=0):
    """
    Returns index of the image with a timestamp previous of the input target
    :param data_in: Dictionary with exif/precise data
    :param datetime_target: Target datetime object in UTC
    :param idx_start: Sample from where the search is initiated. It goes backwards in the list
    :param idx_limit: Last valid sample in the list. To limit the search to part of the data
    :return:  Index of data_in list
    """
    if idx_limit < 0:
        idx_limit = 0

    if idx_start <= idx_limit:
        idx_return = idx_limit
    else:
        idx_return = idx_start + 1 #Loop starts by substracting

        target_found = False
        while not target_found:
            idx_return -= 1
            if idx_return > idx_limit:
                if data_in['timestampMs'][idx_return] <= datetime_target:
                    target_found = True
            else:
                # No more valid samples to analyze
                target_found = True
    return idx_return