The if statement should read
if ((tx+i*4)<=(ox+k*4+4) && (tx+i*4+4)>=(ox+k*4)
&& (ty+j*4)<=(oy+l*4+4) && (ty+j*4+4)>=(oy+l*4+2)
&& mask[i][j] && otherMask[k][l])
Also, looking at the rest of the project, you messed up x and y when initializing the ImageMask.