Trying to apply https://tex.stackexchange.com/a/482980/18401, I stumbled upon a strange error. Indeed, while the following MCE compile like a charm:
\documentclass{beamer}
\newenvironment{theindex}{}{}
\usepackage{imakeidx}
\makeatletter
\def\@idxitem{\par}
\def\imki@firstpagestyle{empty}
\makeatother
\makeindex
\begin{document}
\begin{frame}
index1\index{index1}
index2\index{index2}
\end{frame}
\begin{frame}
index1\index{index1}
% foo\index{foo}
\end{frame}
\begin{frame}
\printindex
\end{frame}
\end{document}
But, as soon as the foo\index{foo} line (quite similar to the above one index2\index{index2}) is uncommented, the compilation fails:
! Undefined control sequence.
l.5 \indexspace
Do you understand what's going on?
\indexspaceis used between letter blocks. Give it a definition (see my answer in the question you linked too).