You could try putting the loops into a function that draws a single square, then call that function for each of the corners in turn
void drawSquare(int top, int left,int width){
int x;
for(x=top; x<=(top+width); x++){
matrix.drawPixel(left, x, LED_ON);
...
}
for(x=left+1; x<=(left+width); x++){
matrix.drawPixel(x, top+width, LED_ON);
...
}
etc...
}