def filterMatches(matches, prevKeypoints, currKeypoints, threshold=30):
  """
  This function discards matches between consecutive frames based on the
  distance between keypoints, which has to be below a certain threshold,
  and based on the fact whether their scale increases (keypoints that 
  don't increase in scale are not useful for TTC). In the paper, the
  threshold for the L2 distance (Euclidean) was 0.25. For ORB, most
  inliers are included (and most outliers excluded) with a threshold
  of 64.
  """

  # queryIdx refers to prevKeypoints, trainIdx refers to currKeypoints
  filteredMatches = list(filter(lambda m: m.distance < threshold and currKeypoints[m.trainIdx].size > prevKeypoints[m.queryIdx].size, matches))

  # Check if length is reasonable
  # print(len(filteredMatches))

  return filteredMatches