function [im1,im2] = query(img,database)

res1=10000000;
res2=10000000;
a=0;
b=0;
%calculate similarity
for i=1:8
    temp = histogramSimilarity(img,database{i});
    if temp<res1
        if temp<res2
            res1=res2;
            res2=temp;
            a = b;
            b = i;
        else
            res1=temp
            a=i;
        end
    end
end
im1=database{b};
im2=database{a};
return;