function NN=LSKnn(X1,X2,ks)
B=750;
[~,N]=size(X2);
NN=zeros(length(ks),N);
DD=zeros(length(ks),N);
for i=1:B:N
  BB=min(B,N-i);
  Dist=distance(X1,X2(:,i:i+BB));
  %[~,nn]=mink(Dist,max(ks));
  [~,nn]=sort(Dist);
  NN(:,i:i+BB)=nn(ks,:);
end;