I only quick glance at your script… but I see several errors straight away…
You only use the bounds of the first artboards[0]…? if they is all different then this must be inside the loop…? ( as size for each )
Just create the one options object and only change the scaling property for each…? ( you have far more than you need here )
Lastly detectSizes() is a function… You have passed it nothing in arguments terms so your variables are out of scope…? ( it no have the slightest idea what scale options are )