human
Complete this python program:
def closest_matches_binocular(ref_pts, pupil_pts, max_dispersion=(1 / 15.0)):
assistant
#Here is the Python program you requested.

    """get pupil positions closest in time to ref points.
    return list of dict with matching ref, pupil0 and pupil1 data triplets.
    """
    ref = ref_pts
    pupil0 = [p for p in pupil_pts if (p['id'] == 0)]
    pupil1 = [p for p in pupil_pts if (p['id'] == 1)]
    pupil0_ts = np.array([p['timestamp'] for p in pupil0])
    pupil1_ts = np.array([p['timestamp'] for p in pupil1])
    def find_nearest_idx(array, value):
        idx = np.searchsorted(array, value, side='left')
        try:
            if (abs((value - array[(idx - 1)])) < abs((value - array[idx]))):
                return (idx - 1)
            else:
                return idx
        except IndexError:
            return (idx - 1)
    matched = []
    if (pupil0 and pupil1):
        for r in ref_pts:
            closest_p0_idx = find_nearest_idx(pupil0_ts, r['timestamp'])
            closest_p0 = pupil0[closest_p0_idx]
            closest_p1_idx = find_nearest_idx(pupil1_ts, r['timestamp'])
            closest_p1 = pupil1[closest_p1_idx]
            dispersion = (max(closest_p0['timestamp'], closest_p1['timestamp'], r['timestamp']) - min(closest_p0['timestamp'], closest_p1['timestamp'], r['timestamp']))
            if (dispersion < max_dispersion):
                matched.append({'ref': r, 'pupil': closest_p0, 'pupil1': closest_p1})
            else:
                print 'to    far.'
    return matched