fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: Ib35eb591534c3f23adc3cb7b7fa9696dc5cbeabf
Reviewed-on: https://gerrit.libreoffice.org/13383
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>