C code that find closest pairs between two samples