def track(image_list, initial_points, remove_bad=True):
    """Track points in image list
    
    Parameters
    ----------------
    image_list : list
            List of images to track in
    initial_points : ndarray
            Initial points to use (in first image in image_list)
    remove_bad : bool
            If True, then the resulting list of tracks will only contain succesfully
            tracked points. Else, it will contain all points present in initial_points.
    
    Returns
    -----------------
    tracks : (N, M, 2) ndarray
            N tracks over M images with (x,y) coordinates of points
    status : (N,) ndarray
            The status of each track. 1 means ok, while 0 means tracking failure
    """
    # Precreate track array
    tracks = np.zeros((initial_points.shape[0], len(image_list), 2), dtype='float32') # NxMx2
    tracks[:,0,:] = np.reshape(np.array(initial_points), [-1,2])
    track_status = np.ones([np.size(initial_points,0),1]) # All initial points are OK
    empty = np.array([])
    window_size = (5,5)
    for i in range(1, len(image_list)):
        img1 = image_list[i-1]
        img2 = image_list[i]
        prev_ok_track = np.flatnonzero(track_status)
        prev_points = tracks[prev_ok_track,i-1,:]
        [points, status, err] = cv2.calcOpticalFlowPyrLK(img1, img2, prev_points, empty, empty, empty, window_size)
        if status is None:
            track_status[:] = 0 # All tracks are bad
            break
        valid_set = np.flatnonzero(status)
        now_ok_tracks = prev_ok_track[valid_set] # Remap
        tracks[now_ok_tracks,i,:] = points[valid_set]
        track_status[prev_ok_track] = status

    if remove_bad:
        final_ok = np.flatnonzero(track_status)
        tracks = tracks[final_ok] # Only rows/tracks with nonzero status
        track_status = track_status[final_ok] 

    return (tracks, track_status)
Track points in image list
    
    Parameters
    ----------------
    image_list : list
            List of images to track in
    initial_points : ndarray
            Initial points to use (in first image in image_list)
    remove_bad : bool
            If True, then the resulting list of tracks will only contain succesfully
            tracked points. Else, it will contain all points present in initial_points.
    
    Returns
    -----------------
    tracks : (N, M, 2) ndarray
            N tracks over M images with (x,y) coordinates of points
    status : (N,) ndarray
            The status of each track. 1 means ok, while 0 means tracking failure