Finds the Euclidean distance between points, if distance is above the threshold, abandons the computation and returns NAN.
Useful links