def get_min_dist(spike_time, spike_train, start_index, t_start, t_end):
    """ Returns the minimal distance |spike_time - spike_train[i]|
    with i>=start_index.
    """
    d = abs(spike_time - t_start)
    if start_index < 0:
        start_index = 0
    while start_index < len(spike_train):
        d_temp = abs(spike_time - spike_train[start_index])
        if d_temp > d:
            return d
        else:
            d = d_temp
        start_index += 1
    # finally, check the distance to end time
    d_temp = abs(t_end - spike_time)
    if d_temp > d:
        return d
    else:
        return d_temp