the problem is that the indices you are adding for the second mesh are not correct, the idea is good, you need to add the indices starting from the last vertex number but the way you've implemented it is wrong, the number of vertices you are getting is considering that of the current mesh too and so it's adding indices pointing to vertices that don't exist yet. the last 2 for loops should look somethign like:
auto prevNumVertices = finalMesh.getNumVertices();
for(auto v: branch.getMesh().getVertices()){
finalMesh.addVertex(v * branch.getGlobalTransformMatrix());
}
for(auto i: branch.getMesh().getIndices()){
finalMesh.addIndex(i + prevNumVertices);
}
or just invert the order so you add the indices first like:
for(auto i: branch.getMesh().getIndices()){
finalMesh.addIndex(i + finalMesh.getNumVertices());
}
for(auto v: branch.getMesh().getVertices()){
finalMesh.addVertex(v * branch.getGlobalTransformMatrix());
}