Making $sth static is intentional.
It allows to prepare() the statement only once, even if using it afterwards billions of times.
Defining it in the sub would imply a heavy performance penalty, even if it would circumvent the problem faced now - but thank you anyway.