Found a way.
Not the smartest one, but it works:
for(i=1;i<=number_squares;i++)
{
roiManager("Select", i-1);
getStatistics(area, mean, min, max);
setThreshold(mean, max);
getSelectionBounds(x,y,w,h);
x=x+w/2;
y=y+h/2;
doWand(x,y);
run("To Bounding Box");
getSelectionBounds(x,y,w,h);
x=x+w/2;
y=y+h/2;
call("ij.Prefs.set", "qa.Re"+i+"x",x);
call("ij.Prefs.set", "qa.Re"+i+"y",y);
resetThreshold();
}
roiManager("Show None");
selectWindow("ROI Manager");
run("Close");

If anyone knows a better way, please comment ^^