idx2, dist = flann.knnSearch(desc1, 2, params={})
mask = dist[:, (0)] / dist[:, (1)] < r_threshold
idx1 = np.arange(len(desc1))
pairs = np.int32(zip(idx1, idx2[:, (0)]))
How to compare surf features in python opencv2.4