# Caption number increases by two for every inclusion

I am trying to typeset my captions in margin using marginpar and captionof. Here is what I get by the MWE. Note the wrong caption numbers.

The first caption is included using macro \fixedmarginpar and the second caption using \marginpar. The figure number gets incremented by 2 for every caption included using \fixedmarginpar.

Please read vspace-in-marginpar-adds-unwanted-vertical-space for the \fixedmarginpar macro used in MWE. This macro sets the caption in a box, and offsets the vertical alignment depending on the height of the box. The caption number is incremented by two because this macro sets a box with caption for calculating the height (\captionof is called for the first time) and then sets it in the marginpar (\captionof is called again). Whats a good workaround?

\documentclass{scrreprt}
\usepackage{calc}
\newcommand{\fixedmarginpar}[2][0pt]{%
\setbox0=\vtop{#2}\marginpar{\vspace{\dimexpr-\ht0+#1}#2}%
}
\begin{document}
\listoffigures

\fixedmarginpar{\captionof{figure}{A}}
\marginpar{\captionof{figure}{A}}
\end{document}

-

\newcommand{\fixedmarginpar}[2][0pt]{%