function [ imagePointsF, error ] = spravPoradiIP( worldPoints, imagePoints )

[pocetDvojicWP,~]=size(worldPoints);
[pocetDvojicIP,~]=size(imagePoints);
error=0;
imagePointsF=[];
if pocetDvojicIP<pocetDvojicWP
    error=1;
    return;
end
pole=0;

for i=1:1:pocetDvojicWP

    for j=1:1:pocetDvojicIP
       pole(j,1:2)=abs(imagePoints(j,1:2)-worldPoints(i,1:2));
    
    end
pole=pole(:,1)+pole(:,2);
[~, index]=min(pole);
imagePointsF(i,1:2)=imagePoints(index,1:2);

end

maxVelikostWP(1,1)=max(worldPoints(:,1));
maxVelikostWP(1,2)=max(worldPoints(:,2));
tolerance=0.3*maxVelikostWP;%tolerance 30% world points

maticePodminek(:,1)=abs(imagePointsF(:,1)-worldPoints(:,1))<tolerance(:,1);
maticePodminek(:,2)=abs(imagePointsF(:,2)-worldPoints(:,2))<tolerance(:,2);

if min(min(maticePodminek))==0
    error=1;
end


end

