Finding the minimum distance between points in a matrix represented by a two-dimensional array of numeric values