Mysql self Join query with Limit never terminates
Your comma between two table means that you make a cross join and then select only the fitting rows.
do a proper JOIN with ON Clause, like
Select Distinct t1.id1, t2.id1 
FROM image as t1 INNER JOIN image as t2 
ON t1.id2 = t2.id2 
LIMIT K;

Also have an index on id2 in the table image