BUG: using index of ref image instead of target image