def pair(s1, s2, track_id_pairs):
    """Returns pairs of tracks, i.e., tracks that can be compared.

    s1 -- all tracks of sensor 1.
    s2 -- all tracks of sensor 2.
    track_id_pairs -- ID pairs of tracks of s1 and s2.

    """
    pairs = []
    # collect available ids of the sensor's tracks
    for tid1, tid2 in track_id_pairs:
        try:
            t1 = s1[tid1]
            t2 = s2[tid2]
            pairs.append([t1, t2])
        except Exception as e:
            # tracks may vanish from view, ignore
            # (pair gets unused at some point)
            pass
    return pairs