Upgraded to return Nx3 matrix of indices