First thing you need to do is store all the images in a cell. The 3 images are stored in cell called templates. Then using idx select the image. The code is shown below.Images are shown in top down fashion.
idx = [3 2 1]; output of knn algorithm
len = length(idx);
templates = {img1,img2,img3}; images stored in cell
for i = 1:len
num = idx(i);
subplot(len,1,i);
imshow(templates{num},[]); shows images as per content of idx
end;
I hope this is what you was searching for...